package com.sdp.irrigation.controller;


import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.sdp.irrigation.db.irrigation_location.service.IIrrigationLocationService;
import com.sdp.irrigation.entity.IrrigationLocation;
import com.sdp.right.entity.SysDictItem;



/**
 * <p>
 * 国家地理信息 前端控制器
 * </p>
 *
 * @author zsp
 * @since 2024-12-14
 */
@RestController
@RequestMapping("/IrrigationLocationController")
public class IrrigationLocationController {
	
	@Autowired
	private IIrrigationLocationService iIrrigationLocationService;

	@GetMapping(value = "/create")
	public void create() {
		List<IrrigationLocation> list = iIrrigationLocationService.list();
		List<SysDictItem> itemList = new ArrayList<SysDictItem>();
		String locationTxt = "D:\\location.txt"; // 文件路径
		for(IrrigationLocation location : list) {
			SysDictItem item = new SysDictItem();
			item.setItemText(location.getLocationName());
			item.setItemValue(location.getLocationNo());
			item.setItemFilter(location.getLocationParentNo());
			itemList.add(item);
			
		}
		
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(locationTxt));
			writer.write(JSONArray.toJSONString(itemList));
			writer.close();
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
}

